﻿using System;
using System.Collections.ObjectModel;
using PairingMatrix.Common.Event;

namespace PairingMatrix.ViewModel
{
    public class DateStripViewModel : ViewModelBase, IDateStripViewModel
    {
        public event DateStripEventHandler DateSelected;

        private readonly DateTime _centerDate;

        public DateStripViewModel(DateTime centerDate)
        {
            _centerDate = centerDate;
            Dates = new ObservableCollection<DateDisplayViewModel> ();
            for(int i = -15; i < 15; i++)
            {
                Dates.Add(new DateDisplayViewModel(_centerDate.AddDays(i)));
            }
            Show = true;
        }

        public ObservableCollection<DateDisplayViewModel> Dates { get; set;}

        private bool show; 
        public bool Show 
        {
            get { return show; }
            set
            {
                if (show == value)
                    return;
                show = value;
                OnPropertyChanged("Show");
            }
        }

        public void RaiseDateSelectedEvent(int days)
        {
           if (DateSelected != null)
                DateSelected(this, new DateStripEventHandlerArgs{Date = _centerDate.AddDays(days)});

        }
    }
}